package com.xbongbong.pro.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 模板设计界面不出现编辑的字段
 *
 * @author long.rao
 * @version v1.0
 * @date 2019/8/27 10:09
 * @since v1.0
 */
@Getter
public enum HideEditableEnum {

    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), Arrays.asList(ContractEnum.PRODUCT_TOTAL.getAttr(), ContractEnum.CONTRACT_COST.getAttr(), ContractEnum.GROSS_PROFIT.getAttr(), ContractEnum.GROSS_PROFIT_RATE.getAttr(), ContractEnum.CASH_PROFIT.getAttr(), ContractEnum.CASH_PROFIT_RATE.getAttr())),
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), Arrays.asList(PurchaseEnum.PRODUCT_TOTAL.getAttr())),
    CUSTOMER(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), Arrays.asList(CustomerManagementEnum.LAST_CONNECT_TIME.getAttr())),
    REFUND(XbbRefTypeEnum.REFUND.getCode(), Arrays.asList(RefundEnum.REFUND_AMOUNT.getAttr())),
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), Arrays.asList(QuotationEnum.PRODUCT_TOTAL.getAttr(), QuotationEnum.ESTIMATE_COST.getAttr(), QuotationEnum.GROSS_PROFIT.getAttr(), QuotationEnum.GROSS_PROFIT_RATE.getAttr(), QuotationEnum.QUOTATION_NO.getAttr())),
    OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), Arrays.asList(SalesOpportunityEnum.COST.getAttr(), SalesOpportunityEnum.GROSS_PROFIT.getAttr(), SalesOpportunityEnum.GROSS_PROFIT_RATE.getAttr())),
    ;

    private Integer type;
    private List<String> attrList;

    HideEditableEnum(Integer type, List<String> attrList) {
        this.type = type;
        this.attrList = attrList;
    }

    public static List<String> getByType(Integer businessType) {
        for (HideEditableEnum hideEditableEnum: values()) {
            if (Objects.equals(hideEditableEnum.getType(), businessType)) {
                return hideEditableEnum.getAttrList();
            }
        }
        return null;
    }
}
